#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define ASCII_ZERO 48
#define ASCII_NINE 57
int main(int argc, char *argv[])
{
    char card_str[19] = {0};
	int array[]	= {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};
	int sum	= 0;
	int i, JYM;
	
    if (argc != 2) {
        printf("Usage:./card 110011191201011111\n");
        exit(-1);
    }

    snprintf(card_str, sizeof(card_str), "%s", argv[1]);
    printf("card string=%s\n", card_str);

	for(i = 0; i < 17; i++){
        if (card_str[i] < ASCII_ZERO || card_str[i] > ASCII_NINE) {
            printf("Please input numeral card number, we are not card the last digit\n");
            exit(-1);
        }
		sum += array[i] * atoi(&card_str[i]);
	}

	JYM = (12 - (sum % 11)) % 11;
    printf("JYM=%d\n", JYM);
    if (JYM == 10) {
        card_str[17] = 'X';
    } else {
        card_str[17] = JYM + ASCII_ZERO;
    }

    printf("The right card number=%s\n", card_str);
	return 0;
}

